<table>
    <thead>
        <tr>
            <th>Nro</th><th>Cédula</th><th>Apellidos</th><th>Nombres</th><th>Carrera</th><th>Ciclo</th><th>Sección</th><th>Paralelo</th><th>TipoMatricula</th><th>Nro Credito</th><th>ValorSemestre</th>
            <th>%Beca</th><th>ValorBeca</th><th>ValorACancelar</th><th>PagoInicial</th><th>Valor Financiado</th><th>NroCuotas</th>
            <th>Cuotas1</th><th>Cuotas2</th><th>Cuotas3</th><th>Cuotas4</th><th>Cuotas5</th><th>CuotasPorCobrar</th><th>ValorPagado</th><th>SaldoACobrar</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $cont = 1;
        $sumaTotal = 0;
        $sumaPagado = 0;
        $total = 0;
        $recargo=0;
        $valorbeca=0;
        $valores_cs=array("c1"=>20,"c2"=>20,"c3"=>20,"c4"=>20,"c5"=>20);

        foreach ($lista["todaLista"] as $file) {
            $couta_c=($tipo==1?count($file["lista_s"]["lista"]):count($file["lista_a"]["lista"]));
            $recargo = round(($file['tipo_matr'] == 1 ? 0 : ($file['tipo_matr'] == 2 ? ($file["costo_semestre_mat"] * 0.1) : ($file["costo_semestre_mat"] * 0.2) )), 2);
            $valorbeca=($file['forma_pago'] == 3 ? $file["costo_semestre_mat"] :($file['forma_pago'] == 4 ? $file["costo_semestre_mat"]*0.75 : 
                        ($file['forma_pago'] == 5 ? $file["costo_semestre_mat"]*0.5 : ($file['forma_pago'] == 6 ? $file["costo_semestre_mat"]*0.25 :0))));
            
            //if($tipo==1){
            //    $couta1_plan_a_c= count($file["lista_s"]["lista"]);
            //}else{
            //    $couta1_plan_a_c= count($file["lista_a"]["lista"]);
            //}
            
            echo '<tr>';
            echo '<td>' . $cont . '</td>';
            echo '<td>' . $file["cedula_pers"] . '</td>';
            echo '<td>' . $file["apellido_pers"] . '</td>';
            echo '<td>' . $file["nombre_pers"] . '</td>';
            echo '<td>' . $file["nombre_car"] . '</td>';
            echo '<td>' . $this->utilidades->numeroCiclo($file["nombre_cic"]) . '</td>';
            $seccion = $this->utilidades->secciones($file["seccion"]);
            echo '<td>' . $seccion["nombre"] . '</td>';
            echo '<td>' . $file["paralelo"] . '</td>';
            echo '<td>' . ($file['tipo_matr'] == 1 ? "ORDINARIA" :($file['tipo_matr'] == 2 ? "EXTRAORDINARIA" : "ESPECIAL")) . '</td>';
            echo '<td>' . $file["nro_credito"] . '</td>';
            
            echo '<td>' . ($file["costo_semestre_mat"]+$recargo) . '</td>';
            echo '<td>' . ($file['forma_pago'] == 3 ? "100" :($file['forma_pago'] == 4 ? "75" : 
                        ($file['forma_pago'] == 5 ? "50" : ($file['forma_pago'] == 6 ? "25" : " ")))) . '</td>';
            echo'<td>' . $valorbeca . '</td>';
            if($tipo==1){
                echo'<td>' . ($file["monto_canc_matr"]+$file["valor_financiar"]) . '</td>';
                echo'<td>' . $file["monto_canc_matr"] . '</td>';
            }else{
                echo'<td>' . ($file["pago_inicial"]+$file["valor_financiar"]) . '</td>';
                echo'<td>' . $file["pago_inicial"] . '</td>';
            }
            
            echo '<td>' .  number_format($file["valor_financiar"], 2, '.', '') . '</td>';

            echo '<td>' . $file["nro_cuotas_plan"] . '</td>';
            $cuotas=array ("c1"=>$file["couta1_plan"],
                "c2"=>$file["couta2_plan"],"c3"=>$file["couta3_plan"],"c4"=>$file["couta4_plan"],
                "c5"=>$file["couta5_plan"]);
            $out=$this->utilidades->ver_couta($couta_c,$cuotas,$valores_cs);
            echo ($out);
            
            //if($tipo==1){
                echo '<td>' . ($file["nro_cuotas_plan"]-$couta_c ) . '</td>';
            //}else{
            //    echo '<td>' . count($file["lista_a"]["lista"]) . '</td>';
            //}
            $sumaTotal+=$file["valor_financiar"];
            if($tipo==1){
                echo '<td>' . number_format($file["lista_s"]["total"], 2, '.', '') . '</td>';
                $sumaPagado+=$file["lista_s"]["total"];
                echo '<td>'. number_format(($file["valor_financiar"]-$file["lista_s"]["total"]), 2, '.', '').'</td>';
            }else{
                echo '<td>' . round(number_format($file["lista_a"]["total"], 2, '.', ''),1) . '</td>';
                $sumaPagado+=$file["lista_a"]["total"];
                echo '<td>'. round(($file["valor_financiar"]-$file["lista_a"]["total"]),1).'</td>';
            }
            
            
            
            //echo '0</td>';
            echo '</tr>';
            $cont++;
        }
        ?>
    </tbody>
</table>